package com.yaorange.web.controller.nongjt;

import com.yaorange.nongjt.domain.NjtYtjPos;
import com.yaorange.nongjt.service.NjtYtjPosService;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.core.page.TableDataInfo;
import com.yaorange.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nongjt/pos")
public class NjtYtjPosController extends BaseController {

    @Autowired
    private NjtYtjPosService njtYtjPosService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('nongjt:pos:list')")
    public TableDataInfo list(NjtYtjPos njtYtjPos) {
        startPage();

        List<NjtYtjPos> list = njtYtjPosService.selectNjtYtjPosList(njtYtjPos);

        return getDataTable(list);
    }

    /**
     * 查询一体打印机服务点列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:pos:list')")
    @GetMapping("/allList")
    public AjaxResult allList()
    {
        return AjaxResult.success(njtYtjPosService.selectNjtYtjPosList(null));
    }

    @PostMapping
    @PreAuthorize("@ss.hasPermi('nongjt:pos:add')")
    @Log(title = "新增一体打印机", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody NjtYtjPos njtYtjPos) {
        int rows = njtYtjPosService.insertNjtYtjPos(njtYtjPos);
        return toAjax(rows);
    }

    @PutMapping
    @PreAuthorize("@ss.hasPermi('nongjt:pos:update')")
    @Log(title = "修改一体打印机", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody NjtYtjPos njtYtjPos) {
        return toAjax(njtYtjPosService.updateNjtYtjPos(njtYtjPos));
    }

    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPermi('nongjt:pos:delete')")
    @Log(title = "批量删除一体打印机", businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable("ids") List<Long> ids) {

        return toAjax(njtYtjPosService.batchDeleteNjtYtjPos(ids));
    }
}
